/**
 * Created by kyee on 17-12-5.
 */
package com.wqj.kyee.mmitest

import android.support.v4.content.ContextCompat
import android.view.Gravity
import android.view.View
import android.widget.Button
import android.widget.LinearLayout
import android.widget.TextView
import org.jetbrains.anko.*
import org.jetbrains.anko.sdk25.coroutines.onClick

/**
 * Created by kyee on 17-12-5.
 */
class NfcUi: AnkoComponent<NfcActivity> {
    val items = arrayOf("NFC","WLAN","LCD屏","触摸屏","音频","摄像头","按钮")
    lateinit var rst_text: TextView

    override fun createView(ui: AnkoContext<NfcActivity>): View {
        return with(ui) {
            verticalLayout {
                backgroundColor = ContextCompat.getColor(ui.ctx, android.R.color.white)

                linearLayout {
                    orientation = LinearLayout.HORIZONTAL
                    textView("请刷nfc") {
                        id = ID_OPT_TEXT
                        textSize = 20f
                    }.lparams {

                        weight = 10f
                    }
                    linearLayout {
                        orientation = LinearLayout.HORIZONTAL
                        button("读") {
                            id = ID_READ_BTN
                        }
                        button("写") {
                            id = ID_WRITE_BTN
                        }
                        button("清空") {
                            id = ID_EMPTY_LOG
                            onClick {
                                rst_text.text = ""
                            }
                        }
                    }.lparams {
                        weight = 1f
                    }
                }.lparams {
                    width = matchParent
                    margin = dip(20)
                    weight = 1f
                }
                rst_text = textView {
                    id = ID_RST_TEXT
                    padding = dip(20)
                    backgroundColor = ContextCompat.getColor(ui.ctx, R.color.colorResult)
                    textSize = 16f
                }.lparams(width = matchParent, height = matchParent) {
                    weight = 10f
                }
            }
        }
    }
    companion object {
        val ID_RST_TEXT: Int = 0
        val ID_EMPTY_LOG: Int = 1
        val ID_OPT_TEXT: Int = 2
        val ID_READ_BTN: Int = 3
        val ID_WRITE_BTN: Int = 4
    }
}